package com.chcplayer.ui
{
import com.chcplayer.FileListModel;
import com.chcplayer.StateColumnModel;
import com.chcplayer.skin.*;

import flash.display.Bitmap;
import flash.display.Sprite;
import flash.display.StageDisplayState;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;

/**
 * author yh
 */
public class ChToolBar extends Sprite
{
	/**
	 */
	public static const BAR_HEIGHT:int = 50;
	/**
	 */
	public static const BTN_SLOT:int = 3;
//--------------------------------------------------------------------------------------------------
// private
//--------------------------------------------------------------------------------------------------
	/**
	 */
	private var m_ttf:TextField = new TextField();
	/**
	 */
	private var m_btnLeft:CHSimpleButton = new CHSimpleButton();
	/**
	 */
	private var m_btnRight:CHSimpleButton = new CHSimpleButton();
	/**
	 */
	private var m_btnCenter:CHSimpleButton = new CHSimpleButton();
	/**
	 */
	private var m_obStateModel:StateColumnModel = new StateColumnModel();
	/**
	 */
	[Embed(source="Assets/Icon/ui/buttonsBg.png")]
	private var m_cBtnBg:Class;
	private var m_picBtnBg:Bitmap;
	/**
	 */
	private var m_obModel:FileListModel;
	/**
	 */
	public function ChToolBar()
	{
		super();
		m_ttf.autoSize = TextFieldAutoSize.LEFT;
		addChild(m_ttf);
		this._init();
	}
//--------------------------------------------------------------------------------------------------
// private
//--------------------------------------------------------------------------------------------------
	private function _init():void
	{
		m_picBtnBg = new m_cBtnBg();
		m_picBtnBg.y = (BAR_HEIGHT - m_picBtnBg.height) >> 1;
		/*
		*/
		this.addChild(m_picBtnBg);
		m_btnLeft.upState = new LeftBtnUPSkin();
		m_btnLeft.overState = new LeftBtnOverSkin();
		m_btnLeft.downState = new LeftBtnDownSkin();
		m_btnLeft.fit2SkinSize();
		m_btnLeft.y = (BAR_HEIGHT - m_btnLeft.height) >> 1;
		/*
		*/
		m_btnRight.upState = new RightBtnUPSkin();
		m_btnRight.overState = new RightBtnOverSkin();
		m_btnRight.downState = new RightBtnDownSkin();
		m_btnRight.fit2SkinSize();
		m_btnRight.y = (BAR_HEIGHT - m_btnRight.height) >> 1;
		/*
		*/
		m_btnCenter.upState = new CenterBtnUPSkin();
		m_btnCenter.overState = new CenterBtnOverSkin();
		m_btnCenter.downState = new CenterBtnDownSkin();
		m_btnCenter.fit2SkinSize();
		m_btnCenter.y = (BAR_HEIGHT - m_btnCenter.height) >> 1;
		/*
		*/
		this.addChild(m_btnLeft);
		this.addChild(m_btnRight);
		this.addChild(m_btnCenter);
		m_btnCenter.addEventListener(MouseEvent.CLICK, click_btn);
	}
	/**
	 */
	public function $move(nT:Number):void
	{
		m_ttf.text = String(nT);
	}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// events
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
	private function click_btn(e:MouseEvent):void
	{
		var obBtn:* = e.target;
		if ( obBtn == m_btnCenter )
		{
			this.stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
		}
	}
//==================================================================================================
// public
//==================================================================================================
	public function setModel(obM:FileListModel):void
	{
		m_obModel = obM;
	}
	/**
	 */
	public function setWidth(nW:int):void
	{
		m_picBtnBg.x = (nW - m_picBtnBg.width) >> 1;
		m_btnCenter.x = (nW - m_btnCenter.width) >> 1;
		m_btnLeft.x = m_btnCenter.x - m_btnLeft.width - BTN_SLOT;
		m_btnRight.x = m_btnCenter.x + m_btnCenter.width + BTN_SLOT;
		this.graphics.clear();
		this.graphics.beginFill(0xd4d0c8);
		this.graphics.drawRect(0, 0, nW, BAR_HEIGHT);
		graphics.endFill();
	}
}
}